package ca.etsmtl.log430.lab1;

/**
 * Class in the management layer for querying the projects' data through the actual project data reader.
 * Plays a role of interface between the Presentation and Data layer
 * @author Adam
 *
 */
public class ProjectAccessManager {
	/**
	 * List of projects.
	 */
    private ProjectList projectList = new ProjectList();

    /**
     * Default
     */
    public ProjectAccessManager() {
    	projectList = null;
    }
    
    /**
     * 
     * @param inputFile
     */
    public ProjectAccessManager(String inputFile) {
    	ProjectReader projectReader = new ProjectReader(inputFile);
    	generateProjecList(projectReader.getListOfProjects());
    }
    
    /**
     * 
     * @param projectDataList
     */
    private void generateProjecList(List listOfProjectDatas)
    {
    	ProjectData projectData;
		Project project;
		listOfProjectDatas.goToFrontOfList();
		
		while ((projectData = (ProjectData)listOfProjectDatas.getItemFromList()) != null)
		{
			project = new Project();
			project.setID(projectData.getId());
			project.setProjectName(projectData.getName());
			project.setStartDate(projectData.getStartDate());
			project.setEndDate(projectData.getEndDate());
			project.setPriority(projectData.getPriority());
			
			// Add the project to the ProjectList
			projectList.addProject(project);
		}
    }
    
    /**
     * 
     * @return
     */
    public ProjectList getListOfProjects()
    {
    	return this.projectList;
    }
}
